/**
 * 
 */
package com.qunar.support.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.qunar.support.util.DBHelper;

/**
 * @author ziqiang.deng
 *
 */
public class AuthorityDao {
	private Connection con;
	
	
	/**
	 * 增加一条权限
	 * @param user_id 用户id
	 * @param menu_id 菜单id
	 * @author ziqiang.deng
	 */
	public void addNewAuthority(int user_id, int menu_id){
		String sql = "INSERT INTO authority (user_id, menu_id) VALUES (?,?);";
			try {
				this.con = DBHelper.getConnection();
				PreparedStatement pstmt = con.prepareStatement( sql );
				pstmt.setInt(1, user_id);
				pstmt.setInt(2, menu_id);
				
				pstmt.executeUpdate();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		
		return ;
	}
	
	/**
	 * 增加一条权限，执行该方法之前必须保证已将用户信息写入数据库
	 * @param user_id 用户id
	 * @param menu_id 菜单id
	 * @author ziqiang.deng
	 */
	public void addNewAuthority(String username, int menu_id){
		//首先根据登录名取得用户id
		String sql = "SELECT id FROM user WHERE login_name = ?;";
		this.con = DBHelper.getConnection();
		try {
			PreparedStatement pstmt = con.prepareStatement( sql );
			pstmt.setString(1, username);
			ResultSet rs = pstmt.executeQuery();
			int id = -1;
			//....go on here
			while( rs.next() ){
				
				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		
		return ;
	}
	
	
}
